@extends('admin.inc.base')
@section('content')
    <ul class="nav nav-tabs">
        <li @if($type== 1)class="active"@endif>
            <a href="/administrator/1/post" >
                已发布
            </a>
        </li>
        <li @if($type == 0)class="active"@endif>
            <a href="/administrator/0/post" >
                草稿
            </a>
        </li>
        <li @if($type == 2)class="active"@endif>
            <a href="/administrator/2/post" >
                回收站
            </a>
        </li>
    </ul>

    <table class="table">
        <tr>
            <th>序号</th>
            <th>标题</th>
            <th>所属分类</th>
            <th>创建时间</th>
            <th>更新时间</th>
            <th>操作</th>
        </tr>
        @foreach($data as $key => $post)
            <tr>
                <td>{{ $key }}</td>
                <td>{{ $post -> title }}</td>
                <td>{{ $cids[$post->cid] }}</td>
                <td>{{ $post -> created_at }}</td>
                <td>{{ $post -> updated_at }}</td>
                <td>
                    @if($type != 0)<a href="javascript:;" class="changeStatus" data-id="{{$post->id}}" data-param="0">草稿</a>@endif
                    @if($type != 2)<a href="javascript:;" class="changeStatus" data-id="{{$post->id}}" data-param="2">回收</a>@endif
                    @if($type != 1)<a href="javascript:;" class="changeStatus" data-id="{{$post->id}}" data-param="1">发布</a>@endif
                    <a href="/administrator/post/{{ $post ->id }}/edit">编辑</a>
                    <a href="/administrator/post/{{ $post ->id }}/delete">删除</a>
                </td>
            </tr>
        @endforeach
    </table>
    <div class="page">{{$data->links()}}</div>

    <script type="text/javascript">
        //更新状态
        $(".changeStatus").click(function(){
            var id = $(this).data('id');
            var param = $(this).data("param");
            $.post("/administrator/post/"+id,{status:param},function(data){
                alert(data.message);
                if(data.state == 'ok'){
                    window.location.reload();
                }
            },'JSON');
        });
    </script>

@endsection